package com.example.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class MQConfig {
//    普通
//    @Bean
//    public CustomExchange exchangeA(){
//        Map<String, Object> map = new HashMap<>(5);
//        map.put("alternate-exchange","exchangeB");
//        map.put("x-delayed-type","direct");
//        return new CustomExchange("A","x-delayed-message",true,true,map);
//    }
//    @Bean
//    public Queue queueA(){
//        Map<String, Object> map = new HashMap<>(5);
//        map.put("x-max-length",10000);
//        map.put("x-dead-letter-exchange","deadexchanage");
//        map.put("x-dead-letter-routing-key","dead");
//        return new Queue("A",false,true,true,map);
//    }
//    @Bean
//    public Binding bindingA(){
//        return BindingBuilder.bind(queueA()).to(exchangeA()).with("ABC").noargs();
//    }
////    备份
//
//    @Bean
//    public FanoutExchange exchangeB(){
//        return new FanoutExchange("B",false,true,null);
//    }
//    @Bean
//    public Queue queueB(){
//        Map<String, Object> map = new HashMap<>(3);
//        map.put("x-max-length",10000);
//        return new Queue("B",false,true,true,map);
//    }
//    @Bean
//    public Binding bindingB(){
//        return BindingBuilder.bind(queueB()).to(exchangeB());
//    }
////    dead
//    @Bean
//    public Exchange deadExchange(){
//        return new FanoutExchange("deadexchanage",false,true,null);
//    }
//    @Bean
//    public Queue deadQueue() {
//        return new Queue("deadQueue", false, true, true, null);
//    }
//    @Bean
//    public Binding bindingDead(){
//        return BindingBuilder.bind(deadQueue()).to(deadExchange()).with("dead").noargs();
//    }
//
//
////    测试扇出交换机
//    @Bean
//    public Queue fanoutQ(){
//        Map<String, Object> map = new HashMap<>();
//        map.put("x-max-priority",10);
//        return new Queue("out",true,false,false,map);
//    }
//    @Bean
//    public FanoutExchange fanoutExchange(){
//        return new FanoutExchange("outtest",true,false,null);
//    }
//    @Bean
//    public Binding bindingOut(){
//        return BindingBuilder.bind(fanoutQ()).to(fanoutExchange());
//    }

    @Bean
    public Binding  Binging(){
      return BindingBuilder.bind(A()).to(directExchange()).with("a");
    }

    @Bean
    public Queue A(){
        return new Queue("consumeA",true,false,false,null);
    }
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("A",true,false,null);
    }
}
